package com.bawei.controller;

import com.bawei.pojo.User;
import com.bawei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/goLogin")
    public String goLogin(){
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date()) +"空你几哇");
        return "login";
    }

    //登录
    @RequestMapping("/login")
    @ResponseBody
    public int login(User user){
        System.out.println("打印内容:"+user);
        return userService.login(user);
    }

    @RequestMapping("/goList")
    public String goList(){
        return "list";
    }

    @RequestMapping("/goRegis")
    public String goRegis(){
        return "regis";
    }

    //注册
    @RequestMapping("/regis")
    @ResponseBody
    public int regis(User user){
        return userService.regis(user);
    }

    //登陆过期跳转页面
    @RequestMapping("/goLoginError")
    public String goLoginError(){
        return "loginError";
    }

    //用户名唯一验证
    @RequestMapping("/findUserName")
    @ResponseBody
    public int findUserName(@RequestParam String userName){
        User user = userService.findUserName(userName);
        if (user!=null){
            return 1;
        }else {
            return 0;
        }
    }
}
